package yhao.demo.web.firstWeb.controller.security;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
import yhao.demo.service.person.apilist.form.PersonEditForm;
import yhao.demo.service.person.apilist.form.PersonInsertForm;
import yhao.demo.service.person.apilist.form.PersonQueryForm;
import yhao.demo.service.person.apilist.model.PersonModel;
import yhao.demo.web.firstWeb.config.ApiSwaggerTags;
import yhao.demo.web.firstWeb.config.AuthorityAnnotation;
import yhao.demo.web.firstWeb.config.AuthorityAnnotationEnums;
import yhao.demo.web.firstWeb.controller.WebBaseController;
import yhao.demo.web.firstWeb.remote.PersonManagerRemote;
import yhao.infra.apilist.validate.IdForm;

/**
 * 人员记录门面层Controller
 * Created by yoara on 2019-03-28
 * //自行修改swagger，权限标识
 */
@Lazy
@RestController
@RequestMapping(value = "/security/person", produces = {"application/json;charset=UTF-8"})
@Api(value = ApiSwaggerTags.DEMO_TAG, description = "人员记录管理相关")
public class PersonManagerController extends WebBaseController {
    @Autowired
    private PersonManagerRemote personManagerRemote;

    @AuthorityAnnotation(AuthorityAnnotationEnums.PERSON_QUERY)
    @GetMapping(value = "/selectById")
    @ApiOperation(value = "获取人员记录信息")
    @ApiResponses({
            @ApiResponse(message = "人员记录信息数据", code = 200, response = PersonModel.class)
    })
    public String selectById(IdForm form) {
        return successInfo(personManagerRemote.selectById(form));
    }

    @AuthorityAnnotation(AuthorityAnnotationEnums.PERSON_EDIT)
    @PostMapping(value = "/insertPerson")
    @ApiOperation(value = "新增人员记录")
    @ApiResponses({
            @ApiResponse(message = "人员记录新增传参数据", code = 200, response = PersonInsertForm.class)
    })
    public String insertPerson(@RequestBody PersonInsertForm form) {
        return successInfo(personManagerRemote.insertPerson(form));
    }

    @AuthorityAnnotation(AuthorityAnnotationEnums.PERSON_EDIT)
    @PostMapping(value = "/editPerson")
    @ApiOperation(value = "编辑人员记录")
    @ApiResponses({
            @ApiResponse(message = "人员记录编辑传参数据", code = 200, response = PersonEditForm.class)
    })
    public String editPerson(@RequestBody PersonEditForm form) {
        return successInfo(personManagerRemote.editPerson(form));
    }

    @AuthorityAnnotation(AuthorityAnnotationEnums.PERSON_QUERY)
    @GetMapping(value = "/queryPersonPage")
    @ApiOperation(value = "查询人员记录分页信息")
    @ApiResponses({
            @ApiResponse(message = "人员记录分页记录", code = 200, response = PersonModel.class)
    })
    public String queryPersonPage(PersonQueryForm form) {
        return successInfo(personManagerRemote.queryPersonPage(form));
    }

    @AuthorityAnnotation(AuthorityAnnotationEnums.PERSON_DELETE)
    @PostMapping(value = "/deleteById")
    @ApiOperation(value = "删除人员记录")
    @ApiResponses({
            @ApiResponse(message = "人员记录删除传参数据", code = 200, response = IdForm.class)
    })
    public String deleteById(@RequestBody IdForm form) {
        return successInfo(personManagerRemote.deleteById(form));
    }
}
